<style lang="less">
@import "./login.less";
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions(['handleLogin', 'getMenus', 'getMainReportData']),
    async handleSubmit ({ userName, password }) {
      const resp = await this.handleLogin({ userName, password })
      console.log(resp)
      if (resp.state === '000') {
        this.getMenus().then(res => {
          if (res.state === '000') {
            this.$router.push({
              name: this.$config.homeName
            })
          } else {
            this.$Message.error(res.data.msg)
          }
        })
      } else {
        this.$Message.error(resp.msg)
      }
    }
  }
}
</script>

<style>
</style>
